package com.hackaton.maps.transport;


import android.graphics.Color;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.PolylineOptions;
import com.hackaton.maps.MapHelper;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Ivan
 * Date: 20.10.13
 * Time: 1:06
 * To change this template use File | Settings | File Templates.
 */
public class Route {

    private TransportType transportType;
    private com.google.android.gms.maps.model.Polyline poly;
    private PolylineOptions polyline = new PolylineOptions();
    public ArrayList<Station> stations = new ArrayList<Station>();
    private int color = 0;

    public Route(TransportType transportType) {
        setTransportType(transportType);
    }

    public void draw(GoogleMap map) {
        polyline = polyline.color(color);
        poly = map.addPolyline(polyline);

        for(int index = 0; index < stations.size(); index++) {
            stations.get(index).draw(map);
        }
    }

    public void setTransportType(TransportType transportType) {
        this.transportType = transportType;
        if (transportType.equals(TransportType.taxi)) {

            color = 0x99ed1c24;
        }
        if (transportType.equals(TransportType.trol)) {
            color = 0x9985db18;
        }
        if (transportType.equals(TransportType.tram)) {
            color = 0x99ef2cc1;
        }
    }

    public void addStation(double x, double y, String address) {
        LatLng position = new LatLng(x, y);
        Station station = new Station(position, this);
        station.address = address;
        station.pointIndex = polyline.getPoints().size();
        addStation(station);
        addPoint(position);
    }

    public void addStation(Station station) {
        stations.add(station);
    }

    public void addPoint(LatLng position) {
        polyline.add(position);
    }

    public void addPoint(double x, double y) {
        addPoint(new LatLng(x, y));
    }

    public TransportType getTransportType() {
        return transportType;
    }

    public void setVisible(boolean value) {
        polyline.visible(value);
        for(int index = 0; index < stations.size(); index++) {
            stations.get(index).setVisible(value);
        }
        // if (!value) {
            poly.setVisible(value);
        // }
    }

    public void toggleVisible() {
        setVisible(!getVisible());
    }

    public boolean getVisible() {
        return polyline.isVisible();
    }
}
